package org.flowcircuit.model


import appearance.DrawContext
import board.Board
import coordinates.{PosDir, Dir, Pos}
import utils.Property


/**
 * 
 * 
 * @author Hans Haggstrom
 */

trait CircuitElement {

  val board = Property[Board]( null, () => onBoardChanged() )

  val pos = Property( Pos(0,0), () => markRedrawNeeded )
  val dir = Property( Dir(0), () => markRedrawNeeded )

  private var _redrawNeeded : Boolean = false

  def redrawNeeded : Boolean = _redrawNeeded
  def markRedrawNeeded() = _redrawNeeded = true
  def markRedrawNotNeeded() = _redrawNeeded = false 

  def posDir : PosDir = PosDir( pos, dir )

  def isInside( queryPos : Pos, context : DrawContext  ) : Boolean

  def render( context : DrawContext )

  protected def onBoardChanged()  {}

}